package day19;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Homework2 {
    public static void main(String[] args) {
        String str="abcdaaaabcdcc";
        String strs="";
        char ch[]=str.toCharArray();
        StringBuilder sb=new StringBuilder();
        System.out.println(Arrays.toString(ch));
        int sum=0;
        for (int i=0;i<ch.length;i++){
            for (int j=0;j<ch.length;j++){
                if (ch[i]==ch[j]){
                    sum++;
                }
            }
            System.out.println("他们最大连续重复字符串为:"+ch[i]+",个数为："+sum);
            sum=0;
        }
    }
}

class MaxConsecutiveChars {
    public static void main(String[] args) {
        String str = "abcdaaaabcdcc";
        char ch[]=str.toCharArray();
        Set set=new HashSet();
        for (char s:ch){
            set.add(s);
        }

        int maxCount = 1;
        int currentCount = 1;
        for (int i = 1; i < str.length(); i++) {
            if (str.charAt(i) == str.charAt(i - 1)) {
                currentCount++;
                if (currentCount > maxCount) {
                    maxCount = currentCount;
                }
            } else {
                currentCount = 1;
            }
        }
        System.out.println("他们最大连续重复字符为:"+set+",最大连续重复字符数为: " + maxCount);
    }
}